package demo2;

//https://www.nowcoder.com/practice/237ae40ea1e84d8980c1d5666d1c53bc?tpId=230&tqId=38965&ru=/exam/oj

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int V = scanner.nextInt();
        int[] dp = new int[V + 1];
        int[] v = new int[n + 1];
        int[] w = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            v[i] = scanner.nextInt();
            w[i] = scanner.nextInt();
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= V; j++) {
                if (j - v[i] >= 0) dp[j] = Math.max(dp[j], dp[j - v[i]] + w[i]);
            }
        }
        System.out.println(dp[V]);

        Arrays.fill(dp, -1);
        dp[0] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= V; j++) {
                dp[j] = dp[j];
                if (j - v[i] >= 0 && dp[j - v[i]] != -1) dp[j] = Math.max(dp[j], dp[j - v[i]] + w[i]);
            }
        }
        if (dp[V] != -1)
            System.out.println(dp[V]);
        else System.out.println(0);
    }
}
